<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *商品管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'店铺类目'),
);
//商品类目
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['id'])){
		$item=pdo_get('jy_wxappjiaoyib_cate',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		$params['f_cat_id']=intval($item['cat_id']);
		$return['params']['id']=intval($_RQ['id']);
	}else{
		$params['f_cat_id']=0;
	}
	if(!empty($_RQ['cat_id'])){
		$params['cat_id']=intval($_RQ['cat_id']);
		$return['params']['cat_id']=intval($_RQ['cat_id']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_wxappjiaoyib_cate',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){

		}
	}	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'《需要开启标准版交易组件》；需申请类目接口权限后，获取类目：https://developers.weixin.qq.com/doc/ministore/minishopspecification/leimuzizhi/qiye.html
		</br>1、《自定义交易组件》《标准交易组件》的区别：https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/Introduction.html
		','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'title','title'=>'类目名称','type'=>'string'),
			array('name'=>'f_cat_id','title'=>'父ID','type'=>'string'),
			array('name'=>'cat_id','title'=>'类目ID','type'=>'string'),
		),'batch'=>array(
			array('type'=>'post','url'=>'/category/updata/','title'=>'同步1级类目'),
			array('type'=>'post','url'=>'/category/updata2/','title'=>'同步2级类目'),
			array('type'=>'post','url'=>'/category/updata3/','title'=>'同步3级类目'),
			array('type'=>'post','url'=>'/category/up_brand/','title'=>'同步品牌'),
		),'action'=>array(
			array('type'=>'href','op'=>'list','title'=>'下级类目'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'type'=>'string','title'=>'类目名称'),
			array('name'=>'cat_id','width'=>15,'type'=>'string','title'=>'类目ID'),
		)
	);
	$return['htmls']=$htmls;
	$status=array('0'=>'显示','1'=>'隐藏');
	$return['status']=$status;
	exi($return);
}
if($_RQ['op']=='updata'){
	$this->model('goods')->upcate();
	exi('同步类目成功！');
}
if($_RQ['op']=='updata2'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'f_cat_id'=>0);
	$list=pdo_getall('jy_wxappjiaoyib_cate',$params);
	if(!$list){
		exi('请先同步1级类目！','error');
	}
	foreach($list as $cv){
		$this->model('goods')->upcate($cv['cat_id'],2);
	}
	exi('同步类目成功！');
}
if($_RQ['op']=='updata3'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'level'=>2);
	$list=pdo_getall('jy_wxappjiaoyib_cate',$params);
	if(!$list){
		exi('请先同步2级类目！','error');
	}
	foreach($list as $cv){
		$this->model('goods')->upcate($cv['cat_id'],3);
	}
	exi('同步类目成功！');
}
if($_RQ['op']=='up_brand'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'level'=>2);
	$list=pdo_getall('jy_wxappjiaoyib_cate',$params);
	if(!$list){
		exi('请先同步2级以上类目！','error');
	}
	$this->model('goods')->up_brand();
	exi('同步品牌成功！');
}